package cn.zero.service.impl;

import cn.zero.domain.Product;
import cn.zero.domain.Store;
import cn.zero.feign.StoreFeignClient;
import cn.zero.mapper.ProductMapper;
import cn.zero.service.IProductServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;

@Service
public class ProductServerImpl implements IProductServer {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private StoreFeignClient storeFeignClient;

    @Override
    public void save(Product product) {
        productMapper.save(product);
        Long id = productMapper.loadByName(product.getName());
        Store store = new Store();
        store.setNumber(product.getNumber());
        store.setProductId(id);
        storeFeignClient.save(store);
    }
}
